* Generates histograms of choices and reversals

clear
set more off
pause on

cd ""


use data_choice_moments

graph drop _all
local scale=300
local var reversal_n
capture sum `var', detail
local med=`r(p50)'
local mean=`r(mean)'
local var risk_reversal_n2
capture sum fe_`var', detail	 
local med_fe=`r(p50)'
local lab="# of reversals in choices"




twoway hist reversal_n, fcolor(green) lcolor(black) freq xlabel(0(5)15) xmtick(0(1)15) discrete start(0) width(1) || scatteri 0 `mean' `scale' `mean', lcolor(red) lpattern(line) c(l) m(i) lwidth(medthick)  || scatteri 0 `med' `scale' `med', lcolor(blue) lpattern(dash) c(l) m(i) lwidth(medthick) legend(label(1 "Reversals") label(2 "Mean") label(3 "Median")) xtitle("`lab'") ytitle("frequency")
graph export g_reversal.pdf,replace






local i=1
foreach var of varlist inv_time_index  inv_lottery_index {
	 capture sum `var', detail
	 local mean=`r(mean)'
	 local med=`r(p50)'


	
	if "`var'"=="inv_time_index" {
		local lab="# of impatient choices"
		local scale=100
		local int=6
		local max=48
		local m_int=1
		local m_max=48			
		}

		
	if "`var'"=="inv_lottery_index" {
		local lab="# of safe choices"
		local scale=75
		local int=5
		local max=55	
		local m_int=1
		local m_max=55			
		}

	local yw=`scale'/4	
	twoway hist `var', freq bin(`m_max') xlabel(0(`int')`max') xmtick(0(`m_int')`m_max') ylabel(0(`yw')`scale') || scatteri 0 `mean' `scale' `mean', lcolor(red) lpattern(dash) c(l) m(i) lwidth(medthick) || scatteri 0 `med' `scale' `med', lcolor(blue) lpattern(dash) c(l) m(i) lwidth(medthick) name(tm`i') legend(label(1 "Frequency") label(2 "Mean") label(3 "Median")) xtitle("`lab'") ytitle("frequency")
	local ++i
	}
	
grc1leg tm2 tm1  
graph export g_choices.pdf,replace

